#建立程序造句子
import FileOpc,random

#形容词
adjective='adjective.txt'
adjectiveList=['crazed','silly','shy','goofy','angry','lazy','obstinate','purple']
#名词
noun='noun.txt'
nounList=['monkey','elephant','cyclist','teacher','author','hockey','player']
#动词短语
verbPhrase='verbPhrase.txt'
verbPhraseList=['played a ukulele','danced a jig','combed his hair','flapped her ears']
#副词短语
adverbPhrase='adverbPhrase.txt'
adverbPhraseList=['on the table','at the groecry store','in the shower','after breakfast','with a broom']

#写入文件
FileOpc.WriteObj(adjective,adjectiveList)
FileOpc.WriteObj(noun,nounList)
FileOpc.WriteObj(verbPhrase,verbPhraseList)
FileOpc.WriteObj(adverbPhrase,adverbPhraseList)

#读取文件
adjectiveInfo = FileOpc.ReadObj(adjective)
nounInfo=FileOpc.ReadObj(noun)
verbPhraseInfo=FileOpc.ReadObj(verbPhrase)
adverbPhraseInfo=FileOpc.ReadObj(adverbPhrase)

#获取随机数
def GetRandomNum(array=[]):
    length = len(array)
    num = random.randint(0,length-1)
    return num
    


#造句程序
isLoop=True

while isLoop:

    isStart=input('是否开始造句？Y/N ')
    if isStart=='y' or isStart=='Y':
        isLoop=True
        adjectiveNum=GetRandomNum(adjectiveInfo)
        nounNum=GetRandomNum(nounInfo)
        verbPhraseNum=GetRandomNum(verbPhraseInfo)
        adverbPhraseNum=GetRandomNum(adverbPhraseInfo)

        adjective_0=adjectiveInfo[adjectiveNum]
        nonu_0=nounInfo[nounNum]
        verbPhrase_0=verbPhraseInfo[verbPhraseNum]
        adverbPhrase_0=adverbPhraseInfo[adverbPhraseNum]

        print('The',adjective_0,nonu_0,verbPhrase_0,adjective_0)
    else:
        isLoop=False
        
#2-询问人的姓名、年龄和最喜欢的颜色，然后将结果保存在一个文件中
print('\n询问人的姓名、年龄和最喜欢的颜色，然后将结果保存在一个文件中')
nameIsEmpty=True
ageIsEmpty=True
favoriteColorIsEmpty=True
info=[]
PeopleInfoName='PeopleInfo.txt'
PeopleInfoName2='PeopleInfo2.txt'

while nameIsEmpty:
    name=input('请输入你的名字：')
    if name!='':
        info.append(name)
        nameIsEmpty=False

    if not nameIsEmpty:
        while ageIsEmpty:
            age=input('请输入你的年龄：')
            if age!='':
                info.append(age)
                ageIsEmpty=False

    if not ageIsEmpty:
        while favoriteColorIsEmpty:
            favoriteColor=input('请输入你最喜欢的颜色：')
            if favoriteColor!='':
                info.append(favoriteColor)
                favoriteColorIsEmpty=False

    if info!='' and len(info)==3:
        tmpStr='\n你的名字是：%s\n你是：%s岁了\n你最喜欢：%s\n'%(info[0],info[1],info[2])

        print(tmpStr)
        FileOpc.WriteInfo(PeopleInfoName,tmpStr)

        FileOpc.WriteObj(PeopleInfoName2,tmpStr)

        FileOpc.ReadObj(PeopleInfoName2)

print()






